use super::connection::{ConnectionConfig, DatabaseConnection};
use anyhow::Result;
use tracing::info;

/// Connection pool wrapper
#[derive(Debug)]
pub struct ConnectionPool {
    connection: DatabaseConnection,
    config: ConnectionConfig,
}

impl ConnectionPool {
    /// Create a new connection pool
    pub async fn new(config: ConnectionConfig) -> Result<Self> {
        info!("Creating connection pool for: {}", config.name);
        
        let connection = DatabaseConnection::new(config.clone()).await?;
        
        Ok(Self {
            connection,
            config,
        })
    }
    
    /// Get a connection from the pool
    pub fn get_connection(&self) -> &DatabaseConnection {
        &self.connection
    }
    
    /// Get pool configuration
    pub fn config(&self) -> &ConnectionConfig {
        &self.config
    }
    
    /// Close the connection pool
    pub async fn close(mut self) {
        info!("Closing connection pool");
        let _ = self.connection.close().await;
    }
}
